package com.css.fxfzysx.modules.vaolEngineering.repository.impl;

import com.css.fxfzysx.modules.vaolEngineering.entity.CpVulnerabilityEntity;
import com.css.fxfzysx.modules.vaolEngineering.param.MainTableParam;
import com.css.fxfzysx.modules.vaolEngineering.repository.PseVulnerabilityRepository;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class PseVulnerabilityRepositoryImpl implements PseVulnerabilityRepository {

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Override
    public void savePseVulnerability(CpVulnerabilityEntity it) {
        jdbcTemplate.update("insert into czt_pse_vulnerability(cpv_id,u,o,floor,intensity,erf,fxerf,fxexp,del_flag,equipment_type,project_id,fxexp_correct,create_time)" +
                "values (?,?,?,?,?,?,?,?,?,?,?,?,?)",it.getCpvId(),it.getU(),it.getO(),it.getFloor(),it.getIntensity(),it.getErf(),it.getFxerf(),it.getFxexp(),it.getDelFlag(),it.getEquipmentType(),it.getProjectId(),it.getFxexpCorrect(),it.getCreateTime());
    }

    @Override
    public boolean deletePseVulnerability(String id) {
        String sql = "update czt_pse_vulnerability set del_flag = '1' where project_id=?";
        return jdbcTemplate.update(sql, id) > 0;
    }

    @Override
    public List<CpVulnerabilityEntity> queryPseVulnerabilityById(String id) {
        String sql = "select * from czt_pse_vulnerability where project_id='"+id+"' and del_flag='0' order by create_time asc";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CpVulnerabilityEntity.class));
    }

    @Override
    public void updateMainTable(MainTableParam mainTableParam) {
        jdbcTemplate.update("update czt_main_table set device_type=?,floor=? where id=?",mainTableParam.getDeviceType(),mainTableParam.getFloor(),mainTableParam.getId());
    }

    @Override
    public void updateValue(CpVulnerabilityEntity it) {
        jdbcTemplate.update("update czt_pse_vulnerability set u=?,o=?,floor=?,intensity=?,erf=?,fxerf=?,fxexp=?,equipment_type=?,fxexp_correct=? where cpv_id=?",
                it.getU(),it.getO(),it.getFloor(),it.getIntensity(),it.getErf(),it.getFxerf(),it.getFxexp(),it.getEquipmentType(),it.getFxexpCorrect(),it.getCpvId());
    }

    @Override
    public List<CpVulnerabilityEntity> getByProjectId(String id) {
        String sql = "select * from czt_pse_vulnerability where project_id = '"+id+"'";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(CpVulnerabilityEntity.class));
    }
}
